$(function(){
	App.code = 'soagov';
	App.ctx = '/' + App.code;

	App.go2 = function(to) {
		switch (to) {
		case '':
		case '#':
//			App.show({
//				ctx: 'soagov',
//				action: 'home'
//			}, $.noop, App.body);
//			break;
			var acts = {};
			acts[C.SVC] = function(d, p, z) {
				d.app = z;
				App.show({
					ctx: 'soagov',
					action: 'svcIndex',
					params: d
				}, $.noop, p);
			}
			acts[C.COM] = function(d, p) {
				App.show({
					ctx: 'soagov',
					action: 'comIndex',
					params: d
				}, $.noop, p);
			}
			acts[C.FACE] = function(d, p) {
				App.show({
					ctx: 'soagov',
					action: 'faceView',
					params: d
				}, $.noop, p);
			}
			var menus = [{
				title : 'soagov首页',
				ctx: 'soagov',
			},{
				title : '新建服务',
				action : 'addSvc',
				no: 7,
				icon: 'icon-newwin'
			},{
				title : '新建接口',
				action : 'addFace',
				no: 8,
				icon: 'icon-newwin'
			},{
				title : '新建组件',
				action : 'addCom',
				no: 9,
				icon: 'icon-newwin'
			}];
			App.show({
				ctx: 'base',
				action: 'dirIndex',
				params: {
					acts: acts,
					menus: menus
				}
			}, $.noop, App.main);
			break;
		case '#envIndex':
			App.show({
				ctx: 'base',
				action: 'envIndex'
			}, $.noop, App.main);
			break;
		case '#flow/edit':
			App.show({
				ctx: 'soagov',
				action: 'flowEdit'
			}, $.noop, App.body);
			break;
		default:
			App.show({
				ctx: 'soagov',
				action: to.substr(1)
			}, $.noop, App.main);
			break;
		}
	}

	App.inits.push(function(){
		App.websocket.on('app', 'inst', 'alert', function(o, e, ws) {
			var ib = App.inbox, ibc = ib.children(), d = o.data;
			if (ibc.length > 3) {
				ibc.first().remove();
			}
			$('<div></div>').click(function(){
				$(this).remove();
			}).append('<span class="icon icon-alert"></span>')
				.append(d.addr + '&nbsp;异常中断').appendTo(ib);
		});
	});
});
